<?php

namespace app\api\model\activity;

use app\api\model\UploadFile;
use app\common\model\activity\LuckyBag as LuckyModel;

class LuckyBag extends LuckyModel
{
    protected $append = [
        'second_image'
    ];

    public function image()
    {
        return $this->hasOne(UploadFile::class, 'file_id', 'image_id')->bind(['image_url' => 'preview_url']);
    }

    public function getSecondImageAttr($value, $data): string
    {
        if(!empty($data['second_image_id'])){
            $result = UploadFile::detail($data['second_image_id'])->toArray();
        }
        return $result['preview_url'] ?? '';
    }
}